
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 06/16/2013 15:11:03
-- Generated from EDMX file: D:\WorkSpace\Code\Wedn.Net\Wedn.Net.Model\DataModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [WednNET];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[W_Comments]', 'U') IS NOT NULL
    DROP TABLE [dbo].[W_Comments];
GO
IF OBJECT_ID(N'[dbo].[W_Links]', 'U') IS NOT NULL
    DROP TABLE [dbo].[W_Links];
GO
IF OBJECT_ID(N'[dbo].[W_Terms]', 'U') IS NOT NULL
    DROP TABLE [dbo].[W_Terms];
GO
IF OBJECT_ID(N'[dbo].[W_UserMetas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[W_UserMetas];
GO
IF OBJECT_ID(N'[dbo].[W_Options]', 'U') IS NOT NULL
    DROP TABLE [dbo].[W_Options];
GO
IF OBJECT_ID(N'[dbo].[W_Posts]', 'U') IS NOT NULL
    DROP TABLE [dbo].[W_Posts];
GO
IF OBJECT_ID(N'[dbo].[W_Relations]', 'U') IS NOT NULL
    DROP TABLE [dbo].[W_Relations];
GO
IF OBJECT_ID(N'[dbo].[W_Users]', 'U') IS NOT NULL
    DROP TABLE [dbo].[W_Users];
GO
IF OBJECT_ID(N'[dbo].[W_PostMetas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[W_PostMetas];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'W_Comments'
CREATE TABLE [dbo].[W_Comments] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [PostId] int  NOT NULL,
    [UserId] int  NOT NULL,
    [AuthorName] nvarchar(32)  NOT NULL,
    [AuthorEmail] varchar(128)  NOT NULL,
    [AuthorUrl] varchar(128)  NOT NULL,
    [PubDate] datetime  NOT NULL,
    [Content] nvarchar(max)  NOT NULL,
    [Status] smallint  NOT NULL,
    [ParentId] int  NOT NULL
);
GO

-- Creating table 'W_Links'
CREATE TABLE [dbo].[W_Links] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Text] nvarchar(32)  NOT NULL,
    [Url] varchar(256)  NOT NULL,
    [Title] nvarchar(64)  NULL,
    [Target] varchar(18)  NOT NULL,
    [Rel] nvarchar(32)  NOT NULL,
    [Type] int  NOT NULL,
    [Visible] bit  NOT NULL,
    [Order] int  NOT NULL,
    [ParentId] int  NOT NULL
);
GO

-- Creating table 'W_Terms'
CREATE TABLE [dbo].[W_Terms] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(32)  NOT NULL,
    [Slug] varchar(256)  NOT NULL,
    [Type] int  NOT NULL,
    [Count] int  NOT NULL,
    [Description] nvarchar(128)  NOT NULL,
    [ParentId] int  NOT NULL
);
GO

-- Creating table 'W_UserMetas'
CREATE TABLE [dbo].[W_UserMetas] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserId] int  NOT NULL,
    [Key] varchar(128)  NOT NULL,
    [Value] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'W_Options'
CREATE TABLE [dbo].[W_Options] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] varchar(128)  NOT NULL,
    [Value] nvarchar(max)  NOT NULL,
    [IsEnable] bit  NOT NULL
);
GO

-- Creating table 'W_Posts'
CREATE TABLE [dbo].[W_Posts] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserId] int  NOT NULL,
    [Slug] varchar(256)  NOT NULL,
    [Title] nvarchar(128)  NULL,
    [PubDate] datetime  NOT NULL,
    [Modified] datetime  NOT NULL,
    [Content] nvarchar(max)  NOT NULL,
    [Excerpt] nvarchar(max)  NOT NULL,
    [Type] smallint  NOT NULL,
    [IsTop] bit  NOT NULL,
    [Status] smallint  NOT NULL,
    [CommentStatus] smallint  NOT NULL,
    [PingStatus] smallint  NOT NULL,
    [Pinged] varchar(max)  NULL,
    [Password] varchar(50)  NULL,
    [ViewCount] int  NOT NULL,
    [CommentCount] int  NOT NULL,
    [ParentId] int  NOT NULL
);
GO

-- Creating table 'W_Relations'
CREATE TABLE [dbo].[W_Relations] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [ObjectId] int  NOT NULL,
    [ObjectType] smallint  NOT NULL,
    [TermId] int  NOT NULL
);
GO

-- Creating table 'W_Users'
CREATE TABLE [dbo].[W_Users] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Login] varchar(64)  NOT NULL,
    [NickName] nvarchar(32)  NOT NULL,
    [Password] varchar(64)  NOT NULL,
    [Email] varchar(128)  NULL,
    [Link] varchar(256)  NULL,
    [RegDate] datetime  NOT NULL,
    [Status] smallint  NOT NULL,
    [Role] int  NOT NULL
);
GO

-- Creating table 'W_PostMetas'
CREATE TABLE [dbo].[W_PostMetas] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [PostId] int  NOT NULL,
    [Key] varchar(128)  NOT NULL,
    [Value] nvarchar(max)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'W_Comments'
ALTER TABLE [dbo].[W_Comments]
ADD CONSTRAINT [PK_W_Comments]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'W_Links'
ALTER TABLE [dbo].[W_Links]
ADD CONSTRAINT [PK_W_Links]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'W_Terms'
ALTER TABLE [dbo].[W_Terms]
ADD CONSTRAINT [PK_W_Terms]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'W_UserMetas'
ALTER TABLE [dbo].[W_UserMetas]
ADD CONSTRAINT [PK_W_UserMetas]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'W_Options'
ALTER TABLE [dbo].[W_Options]
ADD CONSTRAINT [PK_W_Options]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'W_Posts'
ALTER TABLE [dbo].[W_Posts]
ADD CONSTRAINT [PK_W_Posts]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'W_Relations'
ALTER TABLE [dbo].[W_Relations]
ADD CONSTRAINT [PK_W_Relations]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'W_Users'
ALTER TABLE [dbo].[W_Users]
ADD CONSTRAINT [PK_W_Users]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'W_PostMetas'
ALTER TABLE [dbo].[W_PostMetas]
ADD CONSTRAINT [PK_W_PostMetas]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------